package com.zbkj.crmeb.supplier.controller;

// import org.apache.shiro.authz.annotation.RequiresPermissions;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.common.CommonPage;
import com.common.PageParamRequest;
import com.crmeb.core.common.CommonResult;
import com.crmeb.core.exception.CrmebException;
import com.github.pagehelper.PageInfo;
import com.zbkj.crmeb.front.request.ProductRequest;
import com.zbkj.crmeb.front.response.ProductResponse;
import com.zbkj.crmeb.merchant.admin.controller.AdminBaseController;
import com.zbkj.crmeb.merchant.api.controller.ApiBaseController;
import com.zbkj.crmeb.store.request.BusinessApplyRequest;
import com.zbkj.crmeb.store.request.SupplierOpenShopRequest;
import com.zbkj.crmeb.store.request.SupplierStoreProductSearchRequest;
import com.zbkj.crmeb.store.response.BusinessApplyResponse;
import com.zbkj.crmeb.store.response.StoreProductResponse;
import com.zbkj.crmeb.store.response.SupplierOpenShopResponse;
import com.zbkj.crmeb.supplier.model.SupplierOpenShop;
import com.zbkj.crmeb.supplier.service.BusinessApplyService;
import com.zbkj.crmeb.supplier.service.SupplierOpenShopService;


/**
 * 供应商一键开店表
 *
 * @author lss
 * @email didiok@foxmail.com
 * @date 2024-11-18 17:36:49
 */
@Slf4j
@RestController
@RequestMapping("api/admin/supplier/open/shop")
public class FrontOpenShopController extends ApiBaseController {
    @Autowired
    private SupplierOpenShopService supplierOpenShopService;

    @Autowired
    private BusinessApplyService businessApplyService;


    @ApiOperation(value = "小程序端查询一键开店商品")
    @RequestMapping(value = "/listProduct/front", method = RequestMethod.POST)
    public CommonResult<CommonPage<ProductResponse>> frontProductList(@Validated @RequestBody ProductRequest request, @Validated PageParamRequest pageParamRequest, HttpServletRequest servletRequest) {
        CommonPage<ProductResponse> pageInfo = new CommonPage<>();
        log.info("小程序端查询一键开店商品, ProductRequest:{}, PageParamRequest:{}", JSONObject.toJSONString(request), JSONObject.toJSONString(pageParamRequest));
        try {
            request.setMerId(getMerId(servletRequest));
            pageInfo = supplierOpenShopService.frontProductList(request, pageParamRequest);
        }catch (Exception e){
            log.error("小程序端查询一键开店商品错误，", e);
            throw new CrmebException("一键开店商品查询报错");
        }
        return CommonResult.success(pageInfo);
    }

    @ApiOperation(value = "小程序端查询一键开店列表")
    @RequestMapping(value = "/list/front", method = RequestMethod.POST)
    public CommonResult<CommonPage<SupplierOpenShopResponse>> frontList(@Validated @RequestBody SupplierOpenShopRequest request, @Validated PageParamRequest pageParamRequest, HttpServletRequest servletRequest) {
        PageInfo<SupplierOpenShopResponse> pageInfo = new PageInfo<>();
        log.info("小程序端查询一键开店列表, request:{}, PageParamRequest:{}", JSONObject.toJSONString(request), JSONObject.toJSONString(pageParamRequest));
        try {
            request.setMerId(getMerId(servletRequest));
            pageInfo = supplierOpenShopService.frontList(request, pageParamRequest);
        }catch (Exception e){
            log.error("小程序端查询一键开店列表 错误，", e);
            throw new CrmebException("一键开店列表 查询报错");
        }
        return CommonResult.success(CommonPage.restPage(pageInfo));
    }

}
